import $ from 'jquery'


interface PlainObject<T = any> {
    [key: string]: T;
}

// 接口类型和方法
interface BaseType{
    post(data: object, url: string, headers?: object):object;
}

class Jquery implements BaseType{
    post = (data: object, url: string, headers?: PlainObject<string | null | undefined>):object =>{
        if (typeof headers == "undefined" || headers == null) {
            headers = {};
        }
        return $.post({
            url: url,
            type: 'POST',
            contentType: 'application/json',
            headers: headers,
            async: false,
            data: JSON.stringify(data),
            success: function (res) {
              return res
            },
            error : function(res) {
              return res
            },
          })
    }
}

const jquery = new Jquery()


export default jquery;